﻿using Daphne.Modularity.UI;
using Daphne.PagesMetro.ViewModels;
using Daphne.SharedMetro;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Microsoft.Practices.Unity;

namespace Daphne.PagesMetro.Pages
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class EditorPage : PageBase, IInitialization
    {
        public EditorPage()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Initialization
        /// </summary>
        public void OnInitialized()
        {
            // register message for leaving the page
            Messenger.Register<LeavePageMessage>(this,  (obj) =>
                {
                    LeavePage();
                });
            
            // message for redrawing the board
            Messenger.Register<RedrawBoard>(this, (obj) =>
                {
                    uxBoard.SetupBoardImageControl();
                });
            
        }

        /// <summary>
        /// Leaves this page
        /// </summary>
        private void LeavePage()
        {
            if (Frame.CanGoBack)
                Frame.GoBack();
        }

        /// <summary>
        /// Invoke go-back event
        /// </summary>
        protected override void GoBackFired()
        {
            uxBack.Command.Execute(null);
            base.GoBackFired();
        }
    }
}
